package com.ruoyi.web.controller.durian;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.durian.domain.LlOrderInfo;
import com.ruoyi.durian.domain.dto.OrderEvaluateDto;
import com.ruoyi.durian.service.LlOrderInfoService;
import com.ruoyi.durian.service.LlOrderService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/order")
public class OrderController extends BaseController {

    @Resource
    private LlOrderService llOrderService;

    @Resource
    private LlOrderInfoService llOrderInfoService;


    /**
     * 根据订单号查订单信息
     */
    @GetMapping("/order/no/info/{orderNo}")
        public AjaxResult info(@PathVariable Long orderNo) {
        String orderId=orderNo.toString();
        LambdaQueryWrapper<LlOrderInfo> QW = new LambdaQueryWrapper<>();
        QW.eq(LlOrderInfo::getOrderNo, orderId);
        return AjaxResult.success(llOrderInfoService.list(QW));
    }

    /**
     * 结算使用优惠券
     *
     * @param orderId
     * @param couponId
     * @return
     */
    @PostMapping("/coupon/useCoupon")
    public AjaxResult useCoupon(Integer orderId, Integer couponId) {
        return llOrderService.useCoupon(orderId, couponId);
    }

    /**
     * 首页展示的订单
     *
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo list() {
        startPage();
        return getDataTable(llOrderService.selectLsit());
    }

    /**
     * 获取订单列表
     *
     * @return
     */
    @GetMapping("/history/list")
    public TableDataInfo getOrderList() {
        startPage();
        return getDataTable(llOrderInfoService.getOrderList());
    }

    /**
     * 获取进行中订单列表
     *
     * @return
     */
    @GetMapping("/underWay/list")
    public TableDataInfo getUnderWayList() {
        startPage();
        return getDataTable(llOrderInfoService.getUnderWayList());
    }

    /**
     * 获取订单信息
     *
     * @param id
     * @return
     */
    @GetMapping("/info/{id}")
    public AjaxResult getOrderInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(llOrderInfoService.getById(id));
    }

    /**
     * 删除订单
     *
     * @param id
     * @return
     */
    @GetMapping("/delById/{id}")
    public AjaxResult delById(@PathVariable("id") Integer id) {
        return llOrderService.delByOrderId(id);
    }

    @GetMapping("/order/count")
    public Long getOrderCount() {
        return llOrderService.getOrderCount();
    }

    /**
     * 正在进行中的订单数量查询
     *
     * @return
     */
    @GetMapping("/selectCount")
    public Long findOrderIng() {
        return llOrderService.findOrderIng();
    }

    /**
     * 获取当前用户的总里程数
     *
     * @return
     */
    @GetMapping("/selectAllMileage")
    public AjaxResult getAllMileage() {
        return llOrderService.getAllMileage();
    }

    /**
     * 乘客对评价中司机的评价
     */
    @PostMapping("/evaluate")
    public AjaxResult evaluate(@RequestBody OrderEvaluateDto orderEvaluateDto) {
        return llOrderService.evaluate(orderEvaluateDto);
    }
}
